/*
 * MonitorTask.java
 * 
 * last update: 30.01.2010 by Vlad Badoiu
 * 
 * author:	Power(power@kermit.cs.pub.ro)
 * 
 * Obs:
 */
package engine;
import java.util.*;

/**
 * This is the BunchMonitor task activation instruction.
 * It simply creates a new BunchMonitor and attaches the DisplayTask to it.
 */

@SuppressWarnings("serial")
class MonitorTask extends DisplayTask {
	DisplayTask dt;
	Vector<Object> target;

	MonitorTask(NameSpace m, int delayBefore, InstructionDescription desc,
			int defaultBase, Vector<Object> target, DefaultInstruction next){
		super(m, delayBefore, desc, defaultBase, target, next);
		Object o;
		this.defaultBase = defaultBase;
		add(next);
		this.target = new Vector<Object>();
		for (Enumeration<Object> e = target.elements(); e.hasMoreElements(); ) {
			o = e.nextElement();
			if (o != null && o instanceof Expression)
				this.target.addElement(o);
		}
		dt = new DisplayTask(this);
		dt.next = null;
	}

	public void execute()
	throws InterpretTimeException, SimulationStoppedException
	{
		waitToRun();
		xConsole.debug("starting bunchmonitor...");
		xConsole.trace("" + new BunchMonitor(ns, target, dt));
	}
}






